import React, { memo } from 'react'
import { Button, Checkbox, Form, Input } from 'antd';
  import  {deng} from '../api/ins'
  import {useNavigate} from 'react-router-dom'
const Deng = memo(() => {
  const navigate=useNavigate()
  const onFinish = async(values) => {
    let res= await deng(values)
    console.log(res);
    if(res.data.success){
      localStorage.setItem('token',res.data.data.token)
      navigate('/Home')
    }else {
      console.log('账号或者密码错误');
    }
   

  };
  const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
  };
  return (
    <div>
        登录页面
        <Form
    name="basic"
    labelCol={{
      span: 8,
    }}
    wrapperCol={{
      span: 16,
    }}
    style={{
      maxWidth: 600,
    }}
    initialValues={{
      remember: true,
    }}
    onFinish={onFinish}
    onFinishFailed={onFinishFailed}
    autoComplete="off"
  >
    <Form.Item
      label="用户名"
      name="username"
      rules={[
        {
          required: true,
          message: '请输入用户名',
        },
        {
          type:'string',
          min:3,
          max:6,
          message: '用户名长度有误',
        }
      ]}
    >
      <Input />
    </Form.Item>

    <Form.Item
      label="密码"
      name="password"
      rules={[
        {
          required: true,
          message: '请输入密码',
        },
        {
          type:'string',
          min:3,
          max:6,
         
          message: '密码长度有误',
        }
      ]}
    >
      <Input.Password />
    </Form.Item>

    

    <Form.Item
      wrapperCol={{
        offset: 8,
        span: 16,
      }}
    >
      <Button type="primary" htmlType="submit">
        登录
      </Button>
    </Form.Item>
  </Form>
    </div>
  )
})

export default Deng